Skip to content

fix(cli): clear getopt optarg for optional long options#21902

Merged
iluuu1994 merged 1 commit intophp:masterfrom
onthebed:clawoss/fix/getopt-clear-optional-optarg
May 1, 2026
Merged

fix(cli): clear getopt optarg for optional long options#21902
iluuu1994 merged 1 commit intophp:masterfrom
onthebed:clawoss/fix/getopt-clear-optional-optarg

Conversation

@onthebed
Copy link
Copy Markdown
Contributor

php_getopt() left *optarg unchanged when a long option with an optional argument was passed without a value, so the CLI parser could reuse the previous option's argument for --ini.

Clear optarg at the start of php_getopt() and add a regression test that exercises -d foo=bar --ini.

Fixes #21901

@onthebed onthebed requested a review from bukka as a code owner April 28, 2026 19:26
@Girgias
Copy link
Copy Markdown
Member

Girgias commented Apr 29, 2026

CI failures are related.

@iluuu1994 iluuu1994 force-pushed the clawoss/fix/getopt-clear-optional-optarg branch from db9964d to 7276abb Compare May 1, 2026 15:50
Technically this applies to other SAPIs, but CLI is currently the only one with
a flag with an optional value. The PHP getopt() implementation already clears
php_optarg by-hand.

Fixes phpGH-21901
Closes phpGH-21902

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
@iluuu1994 iluuu1994 force-pushed the clawoss/fix/getopt-clear-optional-optarg branch from 7276abb to 893bc0a Compare May 1, 2026 16:57
@iluuu1994 iluuu1994 merged commit 9258123 into php:master May 1, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

php_getopt() does not clear *optarg for long options with optional argument when value is absent — --ini regression in 8.5

3 participants